package com.diandian.coolco.emilie.widget;

import android.content.Context;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;


public class ColorFilterImageView extends ImageView {

    public ColorFilterImageView(Context context) {
        this(context, null, 0);
    }

    public ColorFilterImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ColorFilterImageView(Context context, AttributeSet attrs,
                                int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        int action = event.getAction();

        switch (action) {
            case MotionEvent.ACTION_DOWN: {
                Drawable drawable = getDrawable();
                if (drawable != null) {

                    drawable.setColorFilter(0x80000000, Mode.SRC_ATOP);
                }
                invalidate();
                break;
            }
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP: {
                Drawable drawable = getDrawable();
                if (drawable != null) {

                    getDrawable().clearColorFilter();
                }
                invalidate();
                break;
            }

            default:
                break;
        }
        return super.dispatchTouchEvent(event);
    }

}
